# -*- coding: utf-8 -*-
import unittest
import sys

sys.path.append('../')

from data import *
from reaction import Reaction, Catalyst, Relation


class BaseObjectTestCase(unittest.TestCase):
	def setUp(self):
		populateDB()

	def tearDown(self):
		clearDB()


class ReactionSimpleTestCase(BaseObjectTestCase):
	def runTest(self):
		r = Reaction(1) #the first compound see data for info.
		self.assert_(r != None)

class ReactionBaseTestCase(BaseObjectTestCase):
	def setUp(self):
		BaseObjectTestCase.setUp(self)
		self.r = Reaction(1)

class ReactionRelationsTestCase(ReactionBaseTestCase):
	def runTest(self):
		self.assertEqual(self.r.relations[0].product.name, compound1['name'])
		self.assertEqual(self.r.relations[1].product.name, compound1['name'])

class ReactionPHTestCase(ReactionBaseTestCase):
	def runTest(self):
		self.assertEqual(self.r.pH, reaction1['pH'])

class ReactionTemperatureTestCase(ReactionBaseTestCase):
	def runTest(self):
		self.assertEqual(self.r.temperature, reaction1['temp'])

class ReactionPressureTestCase(ReactionBaseTestCase):
	def runTest(self):
		self.assertEqual(self.r.pressure, reaction1['pressure'])

class ReactionTimeTestCase(ReactionBaseTestCase):
	def runTest(self):
		self.assertEqual(self.r.time, reaction1['time'])

class ReactionSolventTestCase(ReactionBaseTestCase):
	def runTest(self):
		self.assertEqual(self.r.solvent, reaction1['solvent'])

class ReactionStateTestCase(ReactionBaseTestCase):
	def runTest(self):
		self.assertEqual(self.r.state, reaction1['state'])

class ReactionOtherTestCase(ReactionBaseTestCase):
	def runTest(self):
		self.assertEqual(self.r.other, reaction1['other'])

class ReactionReferenceTestCase(ReactionBaseTestCase):
	def runTest(self):
		self.assertEqual(self.r.reference.name, reference1['name'])

class ReactionUpdateTestCase(ReactionBaseTestCase):
	def setUp(self):
		ReactionBaseTestCase.setUp(self)
		self.r.temperature = 4
		c = Catalyst()
		c.insert()
		self.cid = c.id
		c.name = "Test name"
		self.r.addCatalyst(c)

	def runTest(self):
		new_r = Reaction(1)
		self.assertEqual(new_r.temperature, 4)
		ids = [c.id for c in new_r.catalysts]
		self.assert_(self.cid in ids)


class CatalystSimpleTestCase(BaseObjectTestCase):
	def runTest(self):
		c = Catalyst(1) #the first catalyst see data for info.
		self.assert_(c != None)

class CatalystBaseTestCase(BaseObjectTestCase):
	def setUp(self):
		BaseObjectTestCase.setUp(self)
		self.c = Catalyst(1)

class CatalystNameTestCase(CatalystBaseTestCase):
	def runTest(self):
		self.assertEqual(self.c.name, catalyst1['name'])

class CatalystReactionTestCase(CatalystBaseTestCase):
	def runTest(self):
		self.assertEqual(self.c.reaction.pH, reaction1['pH'])


class RelationSimpleTestCase(BaseObjectTestCase):
	def runTest(self):
		r = Relation(1) #the first catalyst see data for info.
		self.assert_(r != None)

class RelationBaseTestCase(BaseObjectTestCase):
	def setUp(self):
		BaseObjectTestCase.setUp(self)
		self.r = Relation(1)

class RelationReactantTestCase(RelationBaseTestCase):
	def runTest(self):
		self.assertEqual(self.r.reactant.name, compound2['name'])

class RelationProductTestCase(RelationBaseTestCase):
	def runTest(self):
		self.assertEqual(self.r.product.name, compound1['name'])

class RelationReactionTestCase(RelationBaseTestCase):
	def runTest(self):
		self.assertEqual(self.r.reaction.pH, reaction1['pH'])

if __name__=="__main__":
	unittest.main()